import 'dart:convert';
import 'dart:io';

import 'package:elec_communication_protocol/elec_communication_protocol.dart';

void main() async {
	final service = DeviceContentDispatchService();
	service.addContents(
		path: 'getResource',
		contentCallback: (query, headers) {
			final file = File('/Users/wangyanxiong/Desktop/22.mp4');
			return file.openRead();
		}
	);
	service.addContents(
		path: 'getSchedule',
		contentCallback: (query, headers) async {
			headers['Content-Length'] = ['406'];
			print('新的计划下载计划');
			return Stream.value(utf8.encode(json.encode({
				'id': 'a123456',
				'name': '临时测试计划',
				'direction': 1,
				'duration': 10000,
				'material_duration': 10000,
				'size': 3733083,
				'createtime': 200120,
				'updatetime': 200120,
				'playOrder': 1,
				'resources': [
//					{
//						'id': 'a123',
//						'name': '测试图片',
//						'scheduleId': 'a123456',
//						'type': 1,
//						'createtime': 200120,
//						'md5': '92d490aa323824ea21178d43b1d94735',
//						'content': 'http://virtual-lightning.com/eduserver/uploadFiles/1.png',
//						'duration': 10000,
//						'size': 1000,
//						'playOrder': 2
//					},
					{
						'id': 'a1234',
						'name': '测试视频',
						'scheduleId': 'a123456',
						'type': 3,
						'createtime': 200120,
						'md5': '964919a6c171c0c1aa0912bc30b349e9',
						'content': 'http://192.168.0.147:10088/22.mp4',
						'duration': 10000,
						'size': 3733083,
						'playOrder': 1
					},
//					{
//						'id': 'a321',
//						'name': '测试文字',
//						'scheduleId': 'a123456',
//						'type': 0,
//						'createtime': 200120,
//						'md5': null,
//						'content': '文字内容测试',
//						'duration': 10000,
//						'size': 0,
//						'playOrder': 1
//					}
				]
			})));
		}
	);
	service.start();
}